//
//  OrderInfoActionView.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/27.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "OrderInfoActionView.h"
#import "ANGradientButton.h"

@interface OrderInfoActionView ()

@property (nonatomic, strong) ANGradientButton *payBtn;
@property (nonatomic, strong) ANGradientButton *cancelBtn;
@property (nonatomic, strong) ANGradientButton *sureBtn;

@end

@implementation OrderInfoActionView

- (void)setType:(int)type
{
    if (type == 0) {
        self.payBtn = [[ANGradientButton alloc] initWithFrame:CGRectMake(0, 0, kWidth(100), kWidth(30))];
        [self.payBtn setTitle:@"去支付" forState:UIControlStateNormal];
        [self.payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.payBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.payBtn];
        
        self.cancelBtn = [[ANGradientButton alloc] initWithFrame:CGRectMake(0, 0, kWidth(100), kWidth(30))];
        [self.cancelBtn setTitle:@"取消订单" forState:UIControlStateNormal];
        [self.cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.cancelBtn];
        
        self.payBtn.layer.cornerRadius = kWidth(15);
        self.payBtn.layer.masksToBounds = YES;
        [self.payBtn addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
        
        self.cancelBtn.layer.cornerRadius = kWidth(15);
        self.cancelBtn.layer.masksToBounds = YES;
        [self.cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-kWidth(15));
//            make.centerY.equalTo(self);
            make.top.equalTo(self).offset(kWidth(10));
            make.width.equalTo(@(kWidth(100)));
            make.height.equalTo(@(kWidth(30)));
        }];
        
        [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.payBtn.mas_left).offset(-kWidth(20));
            make.top.equalTo(self).offset(kWidth(10));
            make.width.equalTo(@(kWidth(100)));
            make.height.equalTo(@(kWidth(30)));
        }];
    }
    else {
        self.sureBtn = [[ANGradientButton alloc] initWithFrame:CGRectMake(0, 0, kWidth(100), kWidth(30))];
        [self.sureBtn setTitle:@"确认收货" forState:UIControlStateNormal];
        [self.sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.sureBtn];
        
        self.sureBtn.layer.cornerRadius = kWidth(15);
        self.sureBtn.layer.masksToBounds = YES;
        
        [self.sureBtn addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-kWidth(15));
            make.top.equalTo(self).offset(kWidth(10));
            make.width.equalTo(@(kWidth(100)));
            make.height.equalTo(@(kWidth(30)));
        }];
    }
}

- (void)payAction:(id)sender
{
    if (self.payHandler) {
        self.payHandler();
    }
}

- (void)cancelAction:(id)sender
{
    if (self.cancelHandler) {
        self.cancelHandler();
    }
}

- (void)sureAction:(id)sender
{
    if (self.sureHandler) {
        self.sureHandler();
    }
}

@end
